package com.example.demo.controller;

import com.example.demo.pojo.Result;
import com.example.demo.pojo.Score;
import com.example.demo.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;


@RestController
@RequestMapping("/score")
public class ScoreController {
    @Autowired
    private ScoreService scoreService;

    @RequestMapping("/addScore")
    public Result addScore(Score score) {

        scoreService.addScore(score);
        return Result.success();
    }

    @RequestMapping("/deleteScore/{studentId}")
    public Result<Integer> deleteScore(Integer studentId) {
        scoreService.deleteScore(studentId);
        return Result.success();
    }

    @RequestMapping("/updateScore")
    public Result<Integer> updateScore( Score score) {
        scoreService.updateScore(score);
        return Result.success();
    }

    @RequestMapping("/getAllScore")
    public Result<List<Score>> getAllScores() {
        List<Score> Scores = scoreService.getAllScores();
        return Result.success(Scores);
    }

    @RequestMapping("/select/{id}")
    public Result<Score> selectScore(@PathVariable("id") Integer studentId) {
        Score score = scoreService.getScoreById(studentId);
        return Result.success(score);
    }
}